#include<bits/stdc++.h>
using namespace std;
int main(){
	freopen("sort.in" , "r" , stdin);
	freopen("sort.out" , "w" , stdout);
	int n , m , f[2010] , h[1010];
	cin >> n >> m;
	int k = 1;
	while(k <= n){
		cin >> f[k];
		k = k + 1;
	}
	int j = 1;
	while(j <= m){
		cin >> h[j];
		j = j + 1;
	}
	int i = 1;
	while(i <= m){
		int r = 1;
		while(h[i] > f[r] && r <= n + i - 1){
			r = r + 1;
		}
		// r = r - 1;
		int l = n + i - 1;
		if(r > l){
			f[r] = h[i];
		}
		else {
			while(l >= r){
				f[l + 1] = f[l];
				l = l - 1;
			}
			f[r] = h[i];	
		}		
		
		i = i + 1;
	}
	int p = 1;
	while(p <= (n + m)){
		cout << f[p] << " ";
		p = p + 1;
	}
	cout << endl;
	return 0;
}